


#ifndef socket_struct_h_
#define socket_struct_h_

#include <pthread.h>




typedef struct {
	int fd;
	struct sockaddr *peer_addr;
	unsigned int sock_addr_size;
	
	const char *pcmd;
	int cmd_str_len;
	int (*upload_cb)(const char *topic, const char *data);
	int (*send_cb)(int fd, const unsigned char *psrc, int len);
	unsigned char cmd_level; // 
}sock_proc_param_t;

typedef sock_proc_param_t server_proc_param_t  ;

typedef void (*send_cb_t)(const sock_proc_param_t *param, const unsigned char *psrc, int len);
/*
typedef struct{
	char ip[16];
	unsigned short port;
	send_cb_t func;
}sock_param_t;

*/

typedef struct {
	int fd;
	struct sockaddr *peer_addr;
	unsigned int sock_addr_size;
	char local_ip[16];
	
	char ip[16];
	unsigned short port;
	unsigned char link_way;
	unsigned char protocol;
	int cmd_level;
	int hearbeat_time;
	int node_workdata_report_interval;
}socket_param_t;

typedef struct {
	pthread_t tid_socket;
	socket_param_t sock_param;
	unsigned char param_change_flag;
	unsigned char socket_exit_flag;
	char new_ip[16];
	int (*rx_proc_cb)(const sock_proc_param_t *param, const socket_param_t *psocket_param);   //  rx data callback function
	int (*cnnt_cb)(const socket_param_t *psocket_param);   // fd 是socket连接的fd
	int (*discnnt_cb)( const socket_param_t *psocket_param);
	int (*timer_cb)(int sec_inc, const socket_param_t *psocket_param);
	int (*cnnt_fail_cb)(int sec_inc, const socket_param_t *psocket_param);
}socket_cb_cfg_t;


#define  CLIENT_OFF_LINE_CNT_SET      30

typedef struct  {
	int		used_flag;
	int 	error_cnt;
	int		off_line_cnt;
	int  	socket_state;   //0 no connet 1 connect
	char 	ip[16];
	int  	port;
	pthread_t    thread_id;

	int		connect_fd;
	int     rcv_timer;
	
}client_socket_t;

/*
typedef struct {
	int fd;
	char *pcmd;
	int cmd_str_len;
	int (*upload_cb)(const char *topic, const char *data);
	unsigned char cmd_level; // 
	
}server_proc_param_t;
*/

#endif

